package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.mapper.BlackListMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListApiImpl implements BlackListApi {
    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageResult findBlackList(Long loginId, Long page, Long pagesize) {
        Page<BlackList> blackListPage = new Page<>(page, pagesize);
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", loginId);
        queryWrapper.orderByDesc("created");
        blackListMapper.selectPage(blackListPage, queryWrapper);
        PageResult<BlackList> pageResult = new PageResult<>();
        pageResult.setPage(page);
        pageResult.setPagesize(pagesize);
        pageResult.setItems(blackListPage.getRecords());
        pageResult.setCounts(blackListPage.getTotal());
        pageResult.setPages(blackListPage.getPages());
        return pageResult;
    }

    @Override
    public void removeBlaceList(Long loginId, Long blackUserId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",loginId);
        queryWrapper.eq("black_user_id",blackUserId);
        blackListMapper.delete(queryWrapper);
    }
}
